import { defHttp } from '/@/utils/http/axios';
// import { orderBy } from 'lodash-es';

import { DictPageListGetResultModel, DictListItem } from './model/systemModel';

enum Api {
  DictPageList = '/admin/dict/page',
  DictPageItemList = '/admin/dict/item/page',
  AddDict = '/admin/dict/add',
  DelDict = '/admin/dict/del',
  UpdateDict = '/admin/dict/update',
  InfoDict = '/admin/dict',
  AddDictItem = '/admin/dict/item/add',
  DelDictItem = '/admin/dict/item/del',
  UpdateDictItem = '/admin/dict/item/update',
  InfoDictItem = '/admin/dict/item',
  DictTypeList = '/admin/dict/type',
}

export const getDictPageListApi = (params) =>
  defHttp.get<DictPageListGetResultModel>({ url: Api.DictPageList, params });

export const getDictPageItemListApi = (params) =>
  defHttp.get<DictPageListGetResultModel>({ url: Api.DictPageItemList, params });

export const addDictApi = (params: DictListItem) =>
  defHttp.post<Boolean>({ url: Api.AddDict, params });

export const updateDictApi = (params: DictListItem) =>
  defHttp.post<never>({ url: Api.UpdateDict, params });

export const deleteDictApi = (id: string) => defHttp.post<Boolean>({ url: Api.DelDict + '/' + id });

export const getDictInfoApi = (id: string) =>
  defHttp.get<Boolean>({ url: Api.InfoDict + '/' + id });

export const addDictItemApi = (params: DictListItem) =>
  defHttp.post<Boolean>({ url: Api.AddDictItem, params });

export const updateDictItemApi = (params: DictListItem) =>
  defHttp.post<never>({ url: Api.UpdateDictItem, params });

export const deleteDictItemApi = (id: string) =>
  defHttp.post<Boolean>({ url: Api.DelDictItem + '/' + id });

export const getDictTypeListApi = async (params: { type: string }) => {
  const ret = defHttp.get<any[]>({ url: Api.DictTypeList + '/' + params.type });
  return ret;
};
